package com.jsoft.controller;

import com.jsoft.entity.Interest;
import com.jsoft.service.InterestService;
import com.jsoft.util.Result;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Interest)表控制层
 *
 * @author makejava
 * @since 2025-03-14 23:30:25
 */
@RestController
@RequestMapping("interest")
public class InterestController {
    /**
     * 服务对象
     */
    @Resource
    private InterestService interestService;

    /**
     * 新增关注
     * @param interestDTO 关注的企业的相关信息
     * @return 插入成功
     */
    @PostMapping("/addInterest")
    public Result addInterest(@RequestBody Interest interestDTO) {
            interestService.addInterest(interestDTO);
            return Result.success();
    }

    /**
     * 查询关注的企业
     * @param userId 用户id
     * @return 查询结果
     */
    @GetMapping("/getInterestedEnterprises")
    public Result<List<Interest>> getInterestedEnterprises(@RequestParam("userId") int userId) {
        List<Interest> lhjdata = interestService.getInterestedEnterprises(userId);
        return Result.success(lhjdata);
    }

    /**
     * 分页查询
     *
     * @param interest 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Interest>> queryByPage(Interest interest, PageRequest pageRequest) {
        return ResponseEntity.ok(this.interestService.queryByPage(interest, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Interest> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.interestService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param interest 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Interest> add(Interest interest) {
        return ResponseEntity.ok(this.interestService.insert(interest));
    }

    /**
     * 编辑数据
     *
     * @param interest 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Interest> edit(Interest interest) {
        return ResponseEntity.ok(this.interestService.update(interest));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.interestService.deleteById(id));
    }

}

